package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.dao.BookDao;
import com.itheima.domain.Book;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author tongchen
 * @create 2022-12-17 17:17
 */
@Service
public class IBookServiceImpl extends ServiceImpl<BookDao, Book> implements IBookService{
    @Autowired
    BookDao bookDao;

    @Override
    public IPage<Book> selectByPage(Integer column ,Integer num) {
        IPage<Book> iPage = new Page<>(column,num);
        bookDao.selectPage(iPage,null);
        return iPage;
    }

    @Override
    public IPage<Book> selectByPage(Integer column, Integer num, Book book) {
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<>();
        lqw.like(Strings.isNotEmpty(book.getName()) ,Book::getName,book.getName());
        lqw.like(Strings.isNotEmpty(book.getType()) ,Book::getType,book.getType());
        lqw.like(Strings.isNotEmpty(book.getDescription()) ,Book::getDescription,book.getDescription());
        IPage<Book> bookPage = new Page<>(column, num);
        bookDao.selectPage(bookPage,lqw);
        return bookPage;
    }
}
